package com.thunbu.lib_common.utils.okhttp;



/**
 * @author hunter
 */

public class BaseResponse<T> {
    private static final String TAG = "BaseResponse";
    public static final String RES_RESULT_SUCCESS = "success";
    private static final int SUCCESS_CODE = 200000;

    private int code;
    private String message;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSussess() {
        if (code == SUCCESS_CODE) {
            return true;
        } else {
           // XLog.e(TAG, this.toString());
            return false;
        }
    }


    @Override
    public String toString() {
        return "BaseResponse{" +
                "code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public static BaseResponse success(){
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setCode(SUCCESS_CODE);
        return baseResponse;
    }

    public static<B> BaseResponse<B> success(B data){
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setCode(SUCCESS_CODE);
        baseResponse.setData(data);
        return baseResponse;
    }

    public static BaseResponse failed(int code, String desc){
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setCode(code);
        baseResponse.setMessage(desc);
        return baseResponse;
    }
}
